home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / examples / xlisp-1.6 / hanoi.lsp < prev    next >
Encoding:
Lisp/Scheme  |  1991-10-06  |  1.7 KB  |  49 lines

  1. ; -*-Lisp-*-
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ; File:         hanoi.lsp
  5. ; RCS:          $Header: $
  6. ; Description:  Good ol towers of hanoi
  7. ;        Usage:
  8. ;            (hanoi <n>)
  9. ;            <n> - an integer the number of discs
  10. ; Author:       ???
  11. ; Created:      Sat Oct  5 20:51:21 1991
  12. ; Modified:     Sat Oct  5 20:52:05 1991 (Niels Mayer) mayer@hplnpm
  13. ; Language:     Lisp
  14. ; Package:      N/A
  15. ; Status:       X11r5 contrib tape release
  16. ;
  17. ; WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  18. ; XLISP version 2.1, Copyright (c) 1989, by David Betz.
  19. ;
  20. ; Permission to use, copy, modify, distribute, and sell this software and its
  21. ; documentation for any purpose is hereby granted without fee, provided that
  22. ; the above copyright notice appear in all copies and that both that
  23. ; copyright notice and this permission notice appear in supporting
  24. ; documentation, and that the name of Hewlett-Packard and Niels Mayer not be
  25. ; used in advertising or publicity pertaining to distribution of the software
  26. ; without specific, written prior permission.  Hewlett-Packard and Niels Mayer
  27. ; makes no representations about the suitability of this software for any
  28. ; purpose.  It is provided "as is" without express or implied warranty.
  29. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  30.  
  31. (defun hanoi(n)
  32.   ( transfer 'A 'B 'C n ))
  33.  
  34. (defun print-move ( from to )
  35.   (princ "Move Disk From ")
  36.   (princ from)
  37.   (princ " To ")
  38.   (princ to)
  39.   (princ "\n"))
  40.  
  41.  
  42. (defun transfer ( from to via n )
  43.   (cond ((equal n 1) (print-move from to ))
  44.     (t (transfer from via to (- n 1))
  45.        (print-move from to)
  46.        (transfer via to from (- n 1)))))
  47.  
  48.  
  49.